package yh;

/**
 * @Author:云尚
 * @Description:方法的重载，求两个数的和
 */
public class OverloadMethod {
    int sum(int a,int b){
        return a+b;
    }
    int sum(int a,int b,int c){
        return a+b+c;
    }
    double sum(double a,double b){
        return a+b;
    }
    double sum(double a,double b,double c){
        return a+b+c;
    }

    public static void main(String[] args) {
        //创建对象
        OverloadMethod overloadMethod=new OverloadMethod();
        /**
         * 调用方法：方法重载
         * 优点：感觉上像是调用一个方法实现了多个功能，实际上还是调用了多个方法
         */
        int result = overloadMethod.sum(1, 2);
        System.out.println(result);
        int result1 = overloadMethod.sum(1, 2, 3);
        System.out.println(result1);
        double result3 = overloadMethod.sum(1.1, 1.2);
        System.out.println(result3);
        double result4 = overloadMethod.sum(1.1, 1.2, 1.3);
        System.out.println(result4);
    }
}
